﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 委托03
{
    /// <summary>
    /// 计算器，作为一个委托
    /// </summary>
    /// <param name="a"></param>
    /// <param name="b"></param>
    /// <returns></returns>
    public delegate double DlgtCounter(double a, double b);

    class Program
    {

        static void Main(string[] args)
        {
            Calcate cal = new Calcate();
            Accountant ac = new Accountant();
            double x = ac.Operation(12, 34, cal.Add);
            Console.WriteLine(x);
            Console.WriteLine(ac.Operation(12, 34, cal.Sub));
        }

    }
    /// <summary>
    /// 会计类
    /// </summary>
    class Accountant
    {
        public double Operation(double a, double b, DlgtCounter dc)
        {
            return dc(a, b);
        }
    }
    /// <summary>
    /// 计算类，里面有加减乘除的方法
    /// </summary>
    class Calcate
    {
        public double Add(double a, double b)
        {
            return a + b;
        }
        public double Sub(double a, double b)
        {
            return a - b;
        }
        public double Mul(double a, double b)
        {
            return a * b;
        }
        public double Div(double a, double b)
        {
            return a / b;
        }
    }
}
